home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / restracklib_0_2.lha / ResTrackLib / opendevice.c < prev    next >
C/C++ Source or Header  |  1994-07-31  |  6KB  |  237 lines

  1. /* opendevice.c */
  2.  
  3. #include <stdio.h>
  4. #include <exec/ports.h>
  5. #include <clib/exec_protos.h>
  6. #ifdef REGARGS
  7. #   include <pragmas/exec_pragmas.h>
  8. #endif
  9.  
  10. #include "restrack_intern.h"
  11.  
  12.  
  13. /*****************************************************************************
  14.  
  15.     NAME
  16.     __rtl_OpenDevice -- allocate memory
  17.  
  18.     SYNOPSIS
  19.     BYTE __rtl_OpenDevice ( UBYTE *devName, ULONG unit,
  20.             struct IORequest *ioRequest, ULONG flags,
  21.             const char * file, int line);
  22.  
  23.     FUNCTION
  24.     Stub for OpenDevice().
  25.  
  26.     HISTORY
  27.     28. Jul 1994    Optimizer   created
  28.  
  29. ******************************************************************************/
  30.  
  31. BYTE __rtl_OpenDevice ( UBYTE *devName, ULONG unit,
  32.         struct IORequest *ioRequest, ULONG flags,
  33.         const char * file, int line)
  34. {
  35.     BYTE ret;
  36.  
  37.     if (!(ret = OpenDevice (devName,unit,ioRequest,flags)) )
  38.     CHECK_ADD_RN3(RTL_EXEC,RTLRT_IORequest,ioRequest,unit,devName)
  39.  
  40.     return (ret);
  41. } /* __rtl_OpenDevice */
  42.  
  43.  
  44. /*****************************************************************************
  45.  
  46.     NAME
  47.     __rtl_CloseDevice
  48.  
  49.     SYNOPSIS
  50.     void __rtl_CloseDevice ( struct IORequest *ioRequest, const char * file,
  51.                 int line);
  52.  
  53.     FUNCTION
  54.     Stub for CloseDevice().
  55.  
  56.     HISTORY
  57.     23. Jul 1994    Optimizer   created
  58.  
  59. ******************************************************************************/
  60.  
  61. void __rtl_CloseDevice ( struct IORequest *ioRequest, const char * file,
  62.             int line)
  63. {
  64.     ResourceNode * node;
  65.  
  66.     if ((node = FindResourceNode1 (ioRequest)) )
  67.     {
  68.     if (node->Resource != RTLRT_IORequest)
  69.     {
  70.         fprintf (stderr, "ERROR: CloseDevice() at %s:%d called for\n",
  71.             file, line);
  72.         PrintResourceNode (node);
  73.     }
  74.     else
  75.     {
  76.         CloseDevice (ioRequest);
  77.         RemoveResourceNode (node);
  78.     }
  79.     }
  80.     else
  81.     CHECK_RT_ERROR_OR_CALL(RTL_EXEC,CloseDevice,"(%p)",ioRequest,
  82.             CloseDevice(ioRequest))
  83.  
  84. } /* __rtl_CloseDevice */
  85.  
  86.  
  87. NRT_RET(BYTE,OpenDevice,(UBYTE *devName, ULONG unit,struct IORequest *ioRequest, ULONG flags),
  88.     (devName,unit,ioRequest,flags))
  89. NRT(CloseDevice,(struct IORequest * ioRequest),(ioRequest))
  90.  
  91. #define RET_FUNC(type,ret,name)                                             \
  92. type __rtl_ ## name (struct IORequest *ioRequest, const char * file,        \
  93.             int line)                        \
  94. {                                        \
  95.     ResourceNode * node;                            \
  96.     type ret;                                    \
  97.                                         \
  98.     if ((node = FindResourceNode1 (ioRequest)) )                            \
  99.     {                                        \
  100.     if (node->Resource != RTLRT_IORequest)                              \
  101.     {                                    \
  102.         fprintf (stderr, "ERROR: " # name "() at %s:%d called for\n",   \
  103.             file, line);                        \
  104.         PrintResourceNode (node);                                       \
  105.     }                                    \
  106.     else                                    \
  107.         ret = name (ioRequest);                                         \
  108.     }                                        \
  109.     else                                    \
  110.     CHECK_RT_ERROR_OR_CALL(RTL_EXEC,name,"(%p)",ioRequest,              \
  111.             ret = name(ioRequest))                                  \
  112.                                         \
  113.     return (ret);                                                           \
  114. }
  115.  
  116. #define FUNC(name)                                                          \
  117. void __rtl_ ## name (struct IORequest *ioRequest, const char * file,        \
  118.             int line)                        \
  119. {                                        \
  120.     ResourceNode * node;                            \
  121.                                         \
  122.     if ((node = FindResourceNode1 (ioRequest)) )                            \
  123.     {                                        \
  124.     if (node->Resource != RTLRT_IORequest)                              \
  125.     {                                    \
  126.         fprintf (stderr, "ERROR: " # name "() at %s:%d called for\n",   \
  127.             file, line);                        \
  128.         PrintResourceNode (node);                                       \
  129.     }                                    \
  130.     else                                    \
  131.         name (ioRequest);                                               \
  132.     }                                        \
  133.     else                                    \
  134.     CHECK_RT_ERROR_OR_CALL(RTL_EXEC,name,"(%p)",ioRequest,              \
  135.             name(ioRequest))                                        \
  136. }
  137.  
  138. RET_FUNC(BYTE,ret,DoIO)
  139. FUNC(SendIO)
  140. RET_FUNC(struct IORequest *,req,CheckIO)
  141. RET_FUNC(BYTE,ret,WaitIO)
  142. FUNC(AbortIO)
  143.  
  144.  
  145. /*****************************************************************************
  146.  
  147.     NAME
  148.     __rtl_CreateIORequest -- allocate memory
  149.  
  150.     SYNOPSIS
  151.     APTR __rtl_CreateIORequest( struct MsgPort *port, ULONG size,
  152.                 const char * file, int line);
  153.  
  154.     FUNCTION
  155.     Stub for CreateIORequest().
  156.  
  157.     HISTORY
  158.     23. Jul 1994    Optimizer   created
  159.  
  160. ******************************************************************************/
  161.  
  162. APTR __rtl_CreateIORequest( struct MsgPort *port, ULONG size,
  163.             const char * file, int line)
  164. {
  165.     ResourceNode * node;
  166.     APTR ioreq;
  167.  
  168.     if ((node = FindResourceNode1 (port)) )
  169.     {
  170.     if (node->Resource != RTLRT_MsgPort)
  171.     {
  172.         fprintf (stderr, "ERROR: CreateIORequest() at %s:%d expected a port but was called with\n",
  173.             file, line);
  174.         PrintResourceNode (node);
  175.     }
  176.     else
  177.     {
  178.         if ( (ioreq = CreateIORequest (port,size)) )
  179.         CHECK_ADD_RN(RTL_EXEC,RTLRT_IORequest,ioreq,size)
  180.     }
  181.     }
  182.     else
  183.     CHECK_RT_ERROR_OR_CALL2(RTL_EXEC,CreateIORequest,"(%p, %ld)",port,size,
  184.                 ioreq=CreateIORequest(port,size))
  185.  
  186.     return (ioreq);
  187. } /* __rtl_CreateIORequest */
  188.  
  189.  
  190. /*****************************************************************************
  191.  
  192.     NAME
  193.     __rtl_DeleteIORequest
  194.  
  195.     SYNOPSIS
  196.     void __rtl_DeleteIORequest( APTR iorequest, const char * file, int line );
  197.  
  198.     FUNCTION
  199.     Stub for __rtl_DeleteIORequest().
  200.  
  201.     HISTORY
  202.     23. Jul 1994    Optimizer   created
  203.  
  204. ******************************************************************************/
  205.  
  206. void __rtl_DeleteIORequest (struct IORequest * mp, const char * file, int line)
  207. {
  208.     ResourceNode * node;
  209.  
  210.     if ((node = FindResourceNode1 (mp)) )
  211.     {
  212.     if (node->Resource != RTLRT_IORequest)
  213.     {
  214.         fprintf (stderr, "ERROR: DeleteIORequest() at %s:%d called for\n",
  215.             file, line);
  216.         PrintResourceNode (node);
  217.     }
  218.     else
  219.     {
  220.         DeleteIORequest (mp);
  221.         RemoveResourceNode (node);
  222.     }
  223.     }
  224.     else
  225.     CHECK_RT_ERROR_OR_CALL(RTL_EXEC,DeleteIORequest,"(%p)",mp, DeleteIORequest(mp))
  226.  
  227. } /* __rlt_DeleteIORequest */
  228.  
  229.  
  230. NRT_RET(APTR,CreateIORequest,(struct MsgPort * port, ULONG size),(port,size))
  231. NRT(DeleteIORequest,(struct MsgPort * mp),(mp))
  232.  
  233.  
  234. /******************************************************************************
  235. *****  ENDE opendevice.c
  236. ******************************************************************************/
  237.